﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Net.Http;
using System.Web.Http;
using WuZu.IBLL;
using System.Web.Security;
using WuZu.Model;
using System.Linq.Expressions;

namespace saimawebapi.Controllers
{

    public class ShowController : ApiController
    {
        private IAdmininfoService AdmininfoService = WuZu.BLLContainer.Container.Resolve<IAdmininfoService>();
        public object Get(string name)
        {
            var data=AdmininfoService.Login(name);
            if(data==null)
            {
                return data;
            }
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(0, data.phone, DateTime.Now, DateTime.Now.AddHours(1), true, string.Format("{0}&{1}", data.phone, data.pwd), FormsAuthentication.FormsCookiePath);
            //返回登录结果，用户信息，用户验证票据信息
            var oUser = new UserInfo { bRes = true, UserName = data.phone, PassWord = data.pwd, Ticket = FormsAuthentication.Encrypt(ticket) };
            //将身份信息保存在session中，验证当前请求是否是有效请求
            HttpContext.Current.Session[data.phone] = oUser;

            return oUser;
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [HttpPost]
        public int Regist1(admininfo m)
        {
           
            var aa = this.AdmininfoService.GetModels(u => u.phone == m.phone).ToList().Count;
            //var isreapet = AdmininfoService.GetModels();
            if(aa>0)
            {
                return 0;
            }
            else
            {
                var result = AdmininfoService.Add(m);
                return 1;
            }
            
         
        }
        public class UserInfo
        {
            public bool bRes { get; set; }
            public string UserName { get; set; }
            public string PassWord { get; set; }
            public string Ticket { get; set; }

        }
    }
}
